const app = getApp();
Page({
  data: {
    src: "",
    width: 250, //裁剪框宽度
    height: 250, //裁剪框高度
  },
  onLoad: function (options) {
    //获取到image-cropper实例
    this.cropper = this.selectComponent("#image-cropper");
    //开始裁剪
    this.setData({
      src: options.pic_src,
    });
  },
  cropperload(e) {
    console.log("cropper初始化完成");
  },
  loadimage(e) {
    console.log("图片加载完成", e.detail);
    //重置图片角度、缩放、位置
    this.cropper.imgReset();
  },
  clickcut(e) {
    //点击裁剪框阅览图片
    wx.previewImage({
      current: e.detail.url, // 当前显示图片的http链接
      urls: [e.detail.url], // 需要预览的图片http链接列表
    });
  },
  onClickEvent() {
    this.cropper.getImg((e) => {
      // app.globalData.picList.push(e.url);
      //app.globalData.currentPic = e.url;
      //console.log(app.globalData);
      wx.redirectTo({
        url: "../picdisplay/picdisplay?pic_src=" + e.url,
      });
    });
  },
  handleCancel() {
    //console.log("cancel");
    wx.navigateBack({
      delta: -1,
    });
  },
  handleRota(e) {
    console.log(e.currentTarget.dataset);
    if (e.currentTarget.dataset.rotadirect == "counterclockwise") {
      //逆时针
      this.rotate(-1);
    } else if (e.currentTarget.dataset.rotadirect == "clockwise") {
      //顺时针
      this.rotate(1);
    }
  },
  rotate(e) {
    //在用户旋转的基础上旋转90°
    if (e > 0) {
      this.cropper.setAngle((this.cropper.data.angle += 90));
    } else {
      this.cropper.setAngle((this.cropper.data.angle -= 90));
    }
  },
  onReady() {},
});
